<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace addons\comments\model;

/**
 * Description of News
 * 评论表
 * @author shilinqing
 */
class Comments extends \web\common\model\BaseModel {

    protected function _initialize() {
        $this->tableName = 'comments';
    }

    public function getCommentsList($pageIndex = -1, $pageSize = -1, $fields = 'a.*', $filter = '', $order = 'id asc') {
        $sql = 'select '.$fields.' from ' . $this->getTableName()  .' a left join tp_member_account as b on b.id=a.user_id left join tp_video c on c.id=a.video_id ';
        if (!empty($filter))
            $sql .= ' where ' . $filter;
        return $this->getDataListBySQL($sql, $pageIndex, $pageSize, $order);
    }

    public function getCommentsTotal($filter = '') {
        $sql = 'select count(*) as c from ' . $this->getTableName()  .' a left join tp_member_account as b on b.id=a.user_id left join tp_video c on c.id=a.video_id';
        if (!empty($filter))
            $sql .= ' where ' . $filter;
        $result = $this->query($sql);
        if (count($result) > 0)
            return intval($result[0]['c']);
        else
            return 0;
    }
}
